package com.bysj.lms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bysj.lms.pojo.entity.LmsFa;
import com.bysj.lms.mapper.LmsFaMapper;
import com.bysj.lms.service.ILmsFaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class LmsFaServiceImpl extends ServiceImpl<LmsFaMapper, LmsFa> implements ILmsFaService {

    @Autowired
    LmsFaMapper lmsFaMapper;

    @Override
    public PageInfo findByPage(String name, int page, int count) {

        PageHelper.startPage(page,count);
        System.out.println(name);
        List<LmsFa> lmsFas = lmsFaMapper.list(name);
        return new PageInfo(lmsFas);
    }

    @Override
    public boolean isExist(String instruNumber) {
        QueryWrapper<LmsFa> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("instru_number",instruNumber);
        LmsFa lmsFa = lmsFaMapper.selectOne(queryWrapper);
        if(lmsFa!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean bind(String instruNumber, Integer rid) {
        boolean update = lambdaUpdate().eq(LmsFa::getInstruNumber,instruNumber).set(LmsFa::getRoom_id, rid).update();
        return update;
    }

    @Override
    public boolean binds(List<String> numbers, String rid) {
        System.out.println(rid);
        numbers.forEach(number-> System.out.println(number));
        int binds = lmsFaMapper.binds(numbers, rid);
        return binds>0?true:false;
    }

    @Override
    public boolean adds(List<LmsFa> list) {
        int adds = lmsFaMapper.adds(list);
        return adds==0?false:true;
    }

    @Override
    public void changeStatus(String status,String number) {
        lambdaUpdate().set(LmsFa::getStatus,status)
                .eq(LmsFa::getInstruNumber,number).update();
    }

    @Override
    public List<LmsFa> LmsFas() {
        List<LmsFa> list = lmsFaMapper.list(null);
        return list;
    }

}
